package love.simbot.example.utils.epidemic;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import love.simbot.example.entity.epidemic.LocationMessage;
import love.simbot.example.utils.http.HttpUtils;

import java.util.HashMap;

// 疫情查询的工具类
public abstract class EpidemicHttpUtils {

    private static final String QUERY_HTTP = "http://ovooa.com/API/yiqing/api";

    public static LocationMessage getEpidemicOfCity(String city){
        HashMap<String,Object> params = new HashMap<>();
        params.put("type","json");
        params.put("msg",city);

        ObjectMapper om = new ObjectMapper();
        om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        LocationMessage message = null;
        try {
            String result = HttpUtils.getTool(QUERY_HTTP, params);
            message = om.readValue(result,LocationMessage.class);
        }catch (Exception e){
            e.printStackTrace();
        }
        return message;
    }

}
